home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Examples / Helpfile / _SQLite_GetTable2d.au3 < prev    next >
Text File  |  2007-09-08  |  2KB  |  53 lines

  1. #include <SQLite.au3>
  2. Local $aResult, $iRows, $iColumns, $iRval
  3.  
  4. _SQLite_Startup ()
  5. If @error > 0 Then
  6.     MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
  7.     Exit - 1
  8. EndIf
  9. _SQLite_Open () ; Open a :memory: database
  10. If @error > 0 Then
  11.     MsgBox(16, "SQLite Error", "Can't Load Database!")
  12.     Exit - 1
  13. EndIf
  14.  
  15. ;Example Table
  16. ;     Name        | Age
  17. ;     -----------------------
  18. ;     Alice       | 43
  19. ;     Bob         | 28
  20. ;     Cindy       | 21
  21.  
  22. If Not _SQLite_Exec (-1, "CREATE TEMP TABLE persons (Name, Age);") = $SQLITE_OK Then _
  23.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  24. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Alice','43');") = $SQLITE_OK Then _
  25.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  26. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Bob','28');") = $SQLITE_OK Then _
  27.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  28. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
  29.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  30.  
  31. ; Query
  32. $iRval = _SQLite_GetTable2d (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
  33. If $iRval = $SQLITE_OK Then
  34.     _SQLite_Display2DResult($aResult)
  35.  
  36. ;~       $aResult looks like this:
  37. ;~  
  38. ;~      Name   Age 
  39. ;~      Alice  43  
  40. ;~      Bob    28  
  41. ;~      Cindy  21  
  42. ;~
  43. ;~    If the dimensions would be switched in _SQLite_GetTable2d the result would look like this:
  44. ;~  
  45. ;~      Name  Alice  Bob  Cindy 
  46. ;~      Age   43     28   21    
  47.  
  48. Else
  49.     MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
  50. EndIf
  51.  
  52. _SQLite_Close ()
  53. _SQLite_Shutdown ()